﻿using System;
using System.Runtime.InteropServices;
using DWORD = System.UInt32;
using WORD = System.UInt16;

namespace JFBG
{
    public class Sense2020
    {
        public Sense2020()
        {

        }

        // 指定DLL文件路径（如果DLL在同一目录下，可以省略路径）
        //3.1 Get DLL Version
        [DllImport("Sense2020Dll.dll", EntryPoint = "DLL_Get_DLL_Versions")]
        private static extern bool DLL_Get_DLL_Versions(ref DWORD pdwDLLVersion);

        //3.2 Initialize Device
        [DllImport("Sense2020Dll.dll", EntryPoint = "DLL_Open_Device")]
        public static extern bool DLL_Open_Device();

        //3.3 Close Device
        [DllImport("Sense2020Dll.dll", EntryPoint = "DLL_Close_Device")]
        private static extern bool DLL_Close_Device();

        //3.4 Get Device Status
        [DllImport("Sense2020Dll.dll", EntryPoint = "DLL_Is_Device_OK")]
        private static extern bool DLL_Is_Device_OK();

        //3.5 Get Device Serial Number
        [DllImport("Sense2020Dll.dll", CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern bool DLL_Get_Device_SN(IntPtr lpszSN);//Buffer size >= 8 bytes

        //3.6 Get Device Hardware and Firmware Revision
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_HW_FW_REV(ref DWORD pdwHW, ref DWORD pdwFW);

        //3.7 Get Device Pixel Count
        [DllImport("Sense2020Dll.dll")]
        private static extern int DLL_Get_Pixel_Count();

        //3.8 Set Sensor Mode
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Set_Sensor_Mode(WORD wSensorMode);

        //3.9 Get Sensor Mode
        [DllImport("Sense2020Dll.dll")]
        private static extern int DLL_Get_Sensor_Mode_Status();

        //3.10 Set Device Integration Time
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Set_Integration_Time_Line_Rate(DWORD dwIntegrationTime, WORD wLineRate);

        //3.11 Get Device Integration Time
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_Integration_Time_Line_Rate(ref DWORD pdwIntegrationTime, ref WORD pwLineRate);

        //3.12 Set Integration times of Multiple Channel  for Auto-Scan
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Set_AutoScan_Integration_Time(ref DWORD pdwIntegrationTime);

        //3.13 Set Optical Switch State
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Set_Optical_Switch(WORD wChannelCount, bool bAutoChannelScan, WORD wChannelIndex);

        //3.14 Get Optical Switch Status
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_Optical_Switch_Status(ref WORD pwChannelCount, ref bool pbAutoChannelScan, ref WORD pwChannelIndex);

        //3.15 Set GPIO State
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Set_GPIO_State(byte byteGPIOState);

        //3.16 Get GPIO State
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_GPIO_State(ref byte pbyteGPIOState);

        //3.17 Calibrate Device with IRS
        [DllImport("Sense2020Dll.dll")]
        private static extern int DLL_IRS_Calibration();

        //3.18 Get Device Temperature
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_Temperature(ref double pdblCaseTemperature, ref double pdblSensorTemperature);

        //3.19 Get Snapshot Spectrum
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_Spectra(ref double pdblData, ref double pdblCaseTemperature);

        //3.20 Load Calibration Data
        [DllImport("Sense2020Dll.dll", CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern bool DLL_Load_Calibration_Data(IntPtr szDeviceSN, IntPtr lpszCalibFilePath);

        //3.21 Get Wavelength Mapping
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_Wavelength(double dblCaseTemperature, ref double pdblWavelength);

        //3.22 Search Peaks in Spectrum
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Search_Peaks(WORD wPeakSearchMode, WORD wPixelCount, ref double pdblWL, ref double pdblPwr, double dblNoiseThreshold, ref double pdblNoiseThresholdProfile,
            ref WORD pwPeakCount, ref double pdblPeakWL, ref double pdblPeakPwr);

        //3.23 Start Constantly Grabbing spectra
        [DllImport("Sense2020Dll.dll")]
        private static extern int DLL_Start_Constantly_Grab_Spectra(bool bAutoScan, bool bExtTrigger, WORD wProcessMode, WORD wPeakSearchMode,
           ref double pdblBackgroundData, ref double pdblNoiseThreshold, ref double pdblNoiseThresholdProfile);

        //3.24 Stop Constantly Grabbing spectra
        [DllImport("Sense2020Dll.dll")]
        private static extern void DLL_Stop_Constantly_Grab_Spectra();

        //3.25 Get the Last Spectra Index
        [DllImport("Sense2020Dll.dll")]
        private static extern string DLL_Get_Last_Spectrum_Index();

        //3.26 Get One Spectrum of a Line Number
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_Constantly_Grab_Spectra(DWORD dwSpectrumIndex, ref DWORD pdwSpectrumLineStamp, ref WORD pwTempType, ref double pdblTemp, ref double pdblPwr);

        //3.27 Get All Peaks Information of One Spectrum at a Line Number
        [DllImport("Sense2020Dll.dll")]
        private static extern bool DLL_Get_Constantly_Grab_Peaks(DWORD dwSpectrumIndex, ref DWORD pdwSpectrumLineStamp, ref WORD pwTempType, ref double pdblTemp, ref WORD pwPeakCount, ref double pdblPeakWL, ref double pdblPeakPwr);

    }


}